package com.hzhjhh.view.manageView.menus.storage;

import java.awt.Frame;
import java.awt.Rectangle;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JTable;
import java.util.Vector;
import javax.swing.JScrollPane;
import javax.swing.table.JTableHeader;

import com.hzhjhh.enums.CategoryEnums;
import com.hzhjhh.init.dialog.Mytable;
import com.hzhjhh.view.manageView.menus.storage.addGoods.AddBt;
import com.hzhjhh.view.manageView.menus.storage.addGoods.CheckTerm;
import com.hzhjhh.view.manageView.menus.storage.addGoods.DeleteBt;
import com.hzhjhh.view.manageView.menus.storage.addGoods.MerchandiseCode;
import com.hzhjhh.view.manageView.menus.storage.addGoods.MerchandiseName;
import com.hzhjhh.view.manageView.menus.storage.addGoods.PurchasePrice;
import com.hzhjhh.view.manageView.menus.storage.addGoods.Remark;
import com.hzhjhh.view.manageView.menus.storage.addGoods.ResetBt;
import com.hzhjhh.view.manageView.menus.storage.addGoods.RetailPrice;
import com.hzhjhh.view.manageView.menus.storage.addGoods.SortId;
import com.hzhjhh.view.manageView.menus.storage.addGoods.Spec;
import com.hzhjhh.view.manageView.menus.storage.addGoods.SubmitBt;
import com.hzhjhh.view.manageView.menus.storage.addGoods.TreatyCode;
import com.hzhjhh.view.manageView.menus.storage.addGoods.Units;
import com.hzhjhh.view.manageView.menus.storage.constant.ShowConstants;

import lombok.Getter;
import lombok.Setter;

import javax.swing.JButton;
import java.awt.Color;

/**
 * 菜单栏初始化-仓库-新增商品-新增商品弹出框
 * 
 * @author 12083
 *
 */
@Getter
@Setter
public class AddGoodsDialog extends JDialog {
	JPanel panel1 = new JPanel();
	JLabel lbMerchandiseCode = MerchandiseCode.lbInit();
	JLabel lbTreatyCode = TreatyCode.lbInit();
	JLabel lbSortId = SortId.lbInit();
	JLabel lbMerchandiseName = MerchandiseName.lbInit();
	JLabel lbRetailPrice = RetailPrice.lbInit();
	JLabel lbSpec = Spec.lbInit();
	JLabel lbUnits = Units.lbInit();
	JLabel lbPurchasePrice = PurchasePrice.lbInit();
	JLabel lbCheckTerm = CheckTerm.lbInit();
	JLabel lbRemark = Remark.lbInit();
	JTextField txfMerchandiseCode = MerchandiseCode.txfInit();
	JTextField txfTreatyCode = TreatyCode.txfInit();
	JTextField txfMerchandiseName = MerchandiseName.txfInit();
	JTextField txfRetailPrice = RetailPrice.txfInit();
	JTextField txfSpec = Spec.txfInit();
	JTextField txfUnits = Units.txfInit();
	JTextField txfPurchasePrice = PurchasePrice.txfInit();
	JTextField txfCheckTerm = CheckTerm.txfInit();
	JTextField txfRemark = Remark.txfInit();
	JScrollPane jScrollPane1 = new JScrollPane();

	JTable jTable1 = new JTable();
	JTableHeader jTableHeader1 = jTable1.getTableHeader();

	Vector colnames = new Vector(); // 表头
	Vector colnames1 = new Vector(); // 测试
	Vector colnames2 = new Vector(); // 测试

	JButton btAdd = AddBt.btInit(this);
	JButton btReset = ResetBt.btInit(this);
	JButton btDelete = DeleteBt.btInit(this);
	JButton btSubmit = SubmitBt.btInit(this);
	JComboBox jComboBox1 = new JComboBox();

	public AddGoodsDialog(Frame owner, String title, boolean modal) {
		super(owner, title, modal);
		try {
			setDefaultCloseOperation(DISPOSE_ON_CLOSE);
			jbInit();
			pack();
		} catch (Exception exception) {
			exception.printStackTrace();
		}
	}

	public AddGoodsDialog() {
		this(new Frame(), "AddGoodsDialog", false);
		this.setSize(900, 480);
		this.setVisible(true);
		this.setTitle("新增商品表");
		this.setLocation(60, 100);
	}

	private void jbInit() throws Exception {
		panel1.setLayout(null);
		for (String desc : CategoryEnums.getDescs()) {
			jComboBox1.addItem(desc);
		}
//		jComboBox1.addItem("生鲜类");
//		jComboBox1.addItem("食品类");
//		jComboBox1.addItem("蔬果类");
//		jComboBox1.addItem("电器类");
//		jComboBox1.addItem("日用类");
//		jComboBox1.addItem("礼品类");
//		txfMerchandiseCode.setBounds(new Rectangle(91, 10, 125, 24));
//		txfTreatyCode.setBounds(new Rectangle(91, 50, 125, 24));
//		txfMerchandiseName.setBounds(new Rectangle(91, 130, 125, 24));
//		txfRetailPrice.setBounds(new Rectangle(91, 170, 125, 24));
//		txfSpec.setBounds(new Rectangle(91, 210, 125, 24));
//		txfUnits.setBounds(new Rectangle(91, 250, 125, 24));
//		txfPurchasePrice.setBounds(new Rectangle(91, 290, 125, 24));
//		txfCheckTerm.setBounds(new Rectangle(91, 330, 125, 24));
//		txfRemark.setBounds(new Rectangle(91, 370, 125, 24));
		jScrollPane1.setBounds(new Rectangle(228, 10, 658, 383));
		panel1.setBackground(Color.pink);
		jComboBox1.setBounds(new Rectangle(91, 90, 125, 24));
		getContentPane().add(panel1);
		panel1.add(lbMerchandiseCode);
		panel1.add(lbTreatyCode);
		panel1.add(lbSortId);
		panel1.add(lbMerchandiseName);
		panel1.add(lbRetailPrice);
		panel1.add(lbSpec);
		panel1.add(lbUnits);
		panel1.add(lbPurchasePrice);
		panel1.add(lbCheckTerm);
		panel1.add(lbRemark);
		panel1.add(txfRetailPrice);
		panel1.add(txfMerchandiseCode);
		panel1.add(txfTreatyCode);
		panel1.add(txfMerchandiseName);
		panel1.add(txfSpec);
		panel1.add(txfUnits);
		panel1.add(txfPurchasePrice);
		panel1.add(txfCheckTerm);
		panel1.add(txfRemark);
		panel1.add(jScrollPane1);
		panel1.add(btSubmit);
		panel1.add(btDelete);
		panel1.add(btReset);
		panel1.add(btAdd);
		panel1.add(jComboBox1);
		jScrollPane1.getViewport().add(jTable1);
		colnames2.add(colnames1);
		jTable1 = Mytable.maketable(colnames2, ShowConstants.ADD_GOODS_HEAD_NAME); // 显示内容
		jScrollPane1.getViewport().add(jTable1);
	}

	Vector addAllData = new Vector();

//	public void jButton1_actionPerformed(ActionEvent e) {
//		if ((jTextField1.getText().length() == 0) || (jTextField2.getText().length() == 0)
//				|| (jTextField4.getText().length() == 0) || (jTextField5.getText().length() == 0)
//				|| (jTextField6.getText().length() == 0) || (jTextField7.getText().length() == 0)
//				|| (jTextField8.getText().length() == 0) || (jTextField9.getText().length() == 0)) {
//			JOptionPane.showMessageDialog(this, "数据填写不完整，请重新填写", "提示", JOptionPane.ERROR_MESSAGE);
//			return;
//		}
//
//		try {
//			Double dj = new Double(jTextField5.getText());
//			Double jhj = new Double(jTextField5.getText());
//			Double bzq = new Double(jTextField5.getText());
//		} catch (Exception ex) {
//			JOptionPane.showMessageDialog(this, "提交的数据不合法，请检查", "提示", JOptionPane.INFORMATION_MESSAGE);
//			return;
//		}
//
//		Vector addData = new Vector();
//		addData.add(jTextField1.getText());
//		addData.add(jTextField2.getText());
//		if (jComboBox1.getSelectedItem().equals("生鲜类")) {
//			addData.add("SX1001");
//		}
//		if (jComboBox1.getSelectedItem().equals("食品类")) {
//			addData.add("SP1002");
//		}
//		if (jComboBox1.getSelectedItem().equals("蔬果类")) {
//			addData.add("SG1003");
//		}
//		if (jComboBox1.getSelectedItem().equals("日用类")) {
//			addData.add("RY1005");
//		}
//		if (jComboBox1.getSelectedItem().equals("礼品类")) {
//			addData.add("LP1006");
//		}
//		if (jComboBox1.getSelectedItem().equals("电器类")) {
//			addData.add("DQ1004");
//		}
//		addData.add(jTextField4.getText());
//		addData.add(jTextField5.getText());
//		addData.add(jTextField6.getText());
//		addData.add(jTextField7.getText());
//		addData.add(jTextField8.getText());
//		addData.add(jTextField9.getText());
//		addData.add(jTextField10.getText());
//		addAllData.add(addData);
//		jTable1 = Mytable.maketable(addAllData, colnames); // 显示内容
//		jScrollPane1.getViewport().add(jTable1);
//	}

//	public void jButton2_actionPerformed(ActionEvent e) {
//		addAllData.removeAllElements();
//		jTable1 = Mytable.maketable(addAllData, colnames); // 显示内容
//		jScrollPane1.getViewport().add(jTable1);
//	}
//
//	public void jButton3_actionPerformed(ActionEvent e) {
//		int row = jTable1.getSelectedRow();
//		addAllData.remove(row);
//		jTable1 = Mytable.maketable(addAllData, colnames); // 显示内容
//		jScrollPane1.getViewport().add(jTable1);
//	}

//	public void jButton4_actionPerformed(ActionEvent e) {
//		Vector addDate1 = new Vector();
//		int i = 0;
//		int number = 0;
//		while (i < addAllData.size()) {
//			addDate1 = (Vector) addAllData.get(i);
//			Double number1 = new Double(addDate1.get(4).toString());
//			Double number2 = new Double(addDate1.get(7).toString());
//			Double number3 = new Double(addDate1.get(8).toString());
//			number = Insert_stock.Insert_merchandise(addDate1.get(0).toString(), addDate1.get(1).toString(),
//					addDate1.get(2).toString(), addDate1.get(3).toString(), number1, addDate1.get(5).toString(),
//					addDate1.get(6).toString(), number2, number3, addDate1.get(9).toString());
//			i++;
//			String str = "第" + i + "条数据写入失败";
//			if (number == 0) {
//				JOptionPane.showMessageDialog(this, str, "提示", JOptionPane.INFORMATION_MESSAGE);
//				return;
//			}
//			if (i == addAllData.size()) {
//				JOptionPane.showMessageDialog(this, "数据提交成功", "提示", JOptionPane.INFORMATION_MESSAGE);
//			}
//
//		}
//	}
}



